package com.chixing.day02_switch_case.test;

public class Work3 {
    /**
     * **3. 给定一个字符串数组 words，请计算当两个字符串 words[i] 和 words[j] 不包含相同字符时，它们长度的乘积的最大值。假设字符串中只包含英语的小写字母。如果没有不包含相同字符的一对字符串，返回 0。**
     * @param args
     */
    public static void main(String[] args) {
        String[] words={"abcw","baz","foo","bar","fxyz","abcdef"};
//        String[] words={"a","ab","abc","d","cd","bcd","abcd"};
//        String[] words={"a","aa","aaa","aaaa"};
        String str="";
        //思路：1.将比较的字符串连接起来
        //     2.indexof()和lastindexof()

        //定义一个最大值
        int max=0;
        for (int i = 0; i < words.length-1; i++) {
            for (int j = i+1; j < words.length; j++) {
                //1)
                str=str.concat(words[i]).concat(words[j]);
                //对连接的字符串进行遍历
                boolean flag=true;
                for (int k = 0; k < str.length(); k++) {
                    //出现两个相同字符
                    if(str.indexOf(str.charAt(k))!=str.lastIndexOf(str.charAt(k))){
                        flag = false;
                        break;
                    }
                }
                //当字符串不重复时
                //做一个备份数组 用于储存下标
//                int[] temp=new int[2];
                if(flag) {
                    //判断最大值的操作
                    if(max<words[i].length() * words[j].length()) {
                        max = words[i].length() * words[j].length();
                    }

                }

                //清空字符串
                str="";
            }
        }
//        System.out.println("两个完全不相同的字符串: " + words[i] + " " + words[j] + " 长度求和为:" + max);
        System.out.println("最大长度求和为:" + max);
    }
}
